﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace DiscoveryLogic.Workflows.Monitor.Avalon.PatientHelper
{
    public class SearchMSNItemCollection : ObservableCollection<SearchMSNItem>
    {
        public event EventHandler SearchMSNItemCostChanged;

        public new void Add(SearchMSNItem item)
        {
            if (item != null)
            {
                item.PropertyChanged += new PropertyChangedEventHandler(SearchMSNItemPropertyChanged);
            }
            base.Add(item);

            RaiseSearchMSNItemCostChanged(this, new EventArgs());
        }

        public new void Remove(SearchMSNItem item)
        {
            base.Remove(item);

            RaiseSearchMSNItemCostChanged(this, new EventArgs());
        }

        private void SearchMSNItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Cost")
            {
                RaiseSearchMSNItemCostChanged(this, new EventArgs());
            }
        }

        void RaiseSearchMSNItemCostChanged(object sender, EventArgs args)
        {
            if (SearchMSNItemCostChanged != null)
            {
                SearchMSNItemCostChanged(sender, args);
            }
        }
    }
}
